package com.yundingai.controller;

import com.yundingai.domain.entity.StudyInfo;
import com.yundingai.domain.entity.vo.ReceiveSubjectListVo;
import com.yundingai.domain.entity.vo.StudyInfoVo;
import com.yundingai.service.StudyInfoService;
import com.yundingai.vm.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/studyInfo")
public class StudyInfoController {
    //用户点击保存学习信息之后，如果是第一次保存，就直接插入数据
    //如果不是第一次保存，就更新数据
    //或者点击保存之后不管是不是第一次，先从数据库查数据，如果没有就新增，有就修改
    //查询已登录用户的userid，

    //前端去获取userid的值，
    @Autowired
    private StudyInfoService studyInfoService;

    @PostMapping("/insertStudyInfo")
    public ResponseResult insertStudyInfo(@RequestBody ReceiveSubjectListVo receiveSubjectListVo) {
        studyInfoService.insertStudyInfo(receiveSubjectListVo);
        return ResponseResult.okResult();
    }

    @GetMapping("/selectStudyInfoByUserId")
    public ResponseResult selectStudyInfoByUserId(Integer userId) {
        StudyInfo userId1 = studyInfoService.selectStudyInfoByUserId(userId);
        return ResponseResult.okResult(userId1);
    }

    @PutMapping("/updateStudyInfo")
    public ResponseResult updateStudyInfo(@RequestBody  ReceiveSubjectListVo receiveSubjectListVo) {
        studyInfoService.updateStudyInfo(receiveSubjectListVo);
        return ResponseResult.okResult();
    }

    @GetMapping("/selectStudyInfoVoByUserId")
    public ResponseResult selectStudyInfoVoByUserId(Integer userId) {
        StudyInfo studyInfo= studyInfoService.selectStudyInfoVoByUserId(userId);
        return ResponseResult.okResult(studyInfo);
    }
}
